package cc.laop.controller.system;

import cc.laop.business.system.ResourceBusiness;
import cc.laop.entity.system.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("admin/system/resource")
public class ResourceController {

	@Autowired
	private ResourceBusiness resourceBusiness;

	@RequestMapping("list.do")
	@ResponseBody
	public Map<String, Object> list() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Resource> reslist = resourceBusiness.select(new Resource());
		map.put("reslist", resourceBusiness.toTree(reslist));
		return map;
	}

	@RequestMapping("addOrEdit.do")
	@ResponseBody
	public Map<String, Object> addOrEdit(Resource res) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("result", resourceBusiness.insertOrUpdate(res));
		return map;
	}

	@RequestMapping("del.do")
	@ResponseBody
	public Map<String, Object> del(Resource res) {
		Map<String, Object> map = new HashMap<String, Object>();
		resourceBusiness.delete(res);
		return map;
	}
}
